package com.meilai.project.mapper.workflow;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.entity.workflow.WorkFlowDefault;
import com.meilai.project.vo.workflow.WorkFlowDefaultListVO;
import com.meilai.project.vo.workflow.WorkFlowTypeNameAndRouterVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface WorkFlowDefaultMapper extends BaseMapper<WorkFlowDefault> {
    @Select("select * from work_flow_default where id=#{id}")
    WorkFlowDefault getById(Integer id);
    @Select("select * from work_flow_default where form_module_id=#{form_module_id}")
    WorkFlowDefault getByFormModuleId(Integer form_module_id);
    @Select("select * from work_flow_default where form_module_id=#{form_module_id} AND company_id=#{company_id}")
    WorkFlowDefault getByFormModuleIdAndCompanyId(Integer form_module_id,Integer company_id);
    @Update("update work_flow_default set flow_json = #{flow_json} where form_module_id=#{form_module_id}")
    Integer updateByFormModuleId(Integer form_module_id,String flow_json);
    @Select("select * from work_flow_default where flow_type=#{flow_type} AND company_id=#{company_id}")
    List<WorkFlowDefault> getByFlowTypeAndCompanyId(Integer flow_type,Integer company_id);
    @Select("select * from work_flow_default where flow_type=#{flow_type} AND company_id=#{company_id} AND status = 1 AND department_id = #{department_id}")
    WorkFlowDefault checkStatus(Integer flow_type,Integer company_id, Integer department_id);
    @Select("select * from work_flow_default where company_id=#{company_id}")
    List<WorkFlowDefault> getByCompanyId(Integer company_id);
    @Update("update work_flow_default set status = #{status} where id=#{id}")
    Integer changeStatus(Integer id,Integer status);
    @Select("select * from work_flow_default where right_id=#{right_id} AND status = 1")
    WorkFlowDefault getByRightId(Integer right_id);
    @Select("select * from work_flow_default where flow_type=#{flow_type} AND company_id=#{company_id} AND status = 1 AND department_id = #{department_id}")
    WorkFlowDefault getByCompanyIdAndFlowType(Integer company_id,Integer flow_type, Integer department_id);
    @Select("SELECT wfd.flow_type,wfd.name,fm.module_path AS router " +
            "FROM work_flow_default wfd  " +
            "JOIN form_module fm ON wfd.form_module_id=fm.id " +
            "WHERE wfd.deleted_at IS NULL AND wfd.`status`=1 " +
            "ORDER BY wfd.flow_type ASC")
    List<WorkFlowTypeNameAndRouterVO> getTypeNameAndRouter();
    @Select("SELECT wfd.flow_type,wfd.name,fm.module_path AS router " +
            "FROM work_flow_default wfd  " +
            "JOIN form_module fm ON wfd.form_module_id=fm.id " +
            "WHERE wfd.deleted_at IS NULL AND wfd.`status`=1 AND wfd.flow_type=#{flow_type}")
    WorkFlowTypeNameAndRouterVO getTypeNameAndRouterByType(@Param("flow_type") Integer flow_type);


    List<WorkFlowDefaultListVO> selectPageList(Page<WorkFlowDefaultListVO> page, @Param("name") String name,
                                        @Param("status") Integer status, @Param("flow_type") Integer flow_type);
}
